﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using System.Runtime.InteropServices;
using Widgetsphere.Generator.Common.Util;
using Widgetsphere.Generator.Common.Forms;
using Widgetsphere.Generator.Common.GeneratorFramework;
using Widgetsphere.Generator.Common.Logging;

namespace Widgetsphere.VsCodeTools
{
	[ComVisible(true)]
	[ComDefaultInterface(typeof(EnvDTE.IDTWizard))]
	[GuidAttribute("0E5A70E0-0A3B-4650-B7C1-B89E28671A28")]
	[ProgId("VSWizard.CreateModelWizard")]
	public class CreateModelWizard : IDTWizard
	{
		public CreateModelWizard()
		{
		}

		#region IDTWizard Members
		public void Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams, ref wizardResult retval)
		{
			try
			{
				WSLog.LogAlways("Start VSCodeToolsPackage");

				NewModelForm F = new NewModelForm();
				if (F.ShowDialog() == System.Windows.Forms.DialogResult.OK)
				{
					string fileName = (string)ContextParams[3] + (string)ContextParams[4];
					GeneratorHelper.SaveModelFile(F.GeneratorProject, fileName);

					EnvDTEHelper.Instance.SetDTE((_DTE)Application);
					FileStateInfo fileStateInfo;
					EnvDTEHelper.Instance.AddProjectItem(fileName, out fileStateInfo);

					retval = wizardResult.wizardResultSuccess;
				}
				else
				{
					retval = wizardResult.wizardResultCancel;
				}
			}
			catch (Exception ex)
			{
				GlobalHelper.SetErr(ex);
				retval = wizardResult.wizardResultFailure;
			}
		}
		#endregion

	}
}